home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / comm.swg / 0041_Simple COM I-O.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-01-27  |  3.3 KB  |  151 lines

  1. {
  2. From: ELAD NACHMAN
  3. Subj: High Speed COM I/O
  4. ---------------------------------------------------------------------------
  5.  RL> Dose anyone know how a humble young TP programmer can access
  6.  RL> modems at speeds of say 57,600 baud rates? I would love even
  7.  RL> 14,400 routines. I had a set of simple I/O routines, but speeds
  8.  RL> over 2400 term programs would lose characters. I would like to
  9.  RL> write some doors for a BBS but can't break the 2400 limit.
  10.  
  11. You probably use a very simple way, which doesn't envolves capturing the
  12. modem's Com port IRQ. That's why you use chars over faster transmitions.
  13. To make sure the program will be fast, optimize it to assembler, or at least
  14. use I/O Ports manipulations (If you odn't use it already).
  15. A cut from a source I have here (Design for com1, if you need support for other
  16. ports use a guide such as Helppc. If you want To write Doors for BBSes you
  17. better use Fossil functions, For that either use Fsildoc.??? (It's in several
  18. FTP sites) or Ralf Brown's Interrupt list):
  19. }
  20.  
  21. const
  22.  
  23. { 8250 IRQ Registers }
  24.  
  25. Data=$03f8; { Contains 8 bits for send/receive }
  26.  
  27. IER=$03f9; { Enables Serial Port when set to 1 }
  28.  
  29. LCR=$03fb; { Sets communication Parameters }
  30.  
  31. MCR=$03FC; { bits 1,2,4 are turned on to ready modems }
  32.  
  33. LSR=$3FD; { when bit 6 is on, it is safe to send a byte }
  34.  
  35. MDMMSR=$03FE; { initialized to $80 when starting }
  36.  
  37. ENBLRDY=$01; { initial value for port[IER] }
  38.  
  39. MDMMOD=$0b; { initial value for port[MCR] }
  40.  
  41. MDMCD=$80; { initial value for port[MDMMSR] }
  42.  
  43. INTCTLR=$21; { port for 8259 interrupt controller }
  44.  
  45. var
  46.  
  47. mybyte:byte;
  48. vector:pointer;
  49.  
  50.  
  51. procedure asyncint; interrupt;
  52. begin
  53. inline($FB); {STI}
  54. mybyte:=port[dataport];
  55. inline($FA); {CLI}
  56.  
  57. Port[$20]:=$20;
  58.  
  59. end;
  60.  
  61. procedure setmodem;
  62. var
  63. regs: registers;
  64. parm : byte;
  65.  
  66. begin
  67.  
  68. parm:=3+4+0+$d0;
  69. {8 databits,1 stopbit,no parity,9600 baud}
  70. {databits: values 0,1,2,3 represent 5,6,7,8 databits
  71. stopbits: value 4 is for 1 stopbits, 0 for none
  72. parity: value 0 or $10 for none, $8 for odd, $18 for even
  73. baud: $d0 for 9600, $b0 for 4800, $a0 for 2400, $80 for 1200, $60 for 600, $40
  74. for 300 add all this values and get the correct byte parameter}
  75.  
  76. with regs do
  77. begin
  78. dx:=0; { comport -1 }
  79. ah:=0;
  80. al:=parm;
  81. flags:=0;
  82. intr($14,regs);
  83. end;
  84. end;
  85.  
  86. procedure EnablePorts;
  87. var
  88. b: byte;
  89. begin
  90. getintvec($0c,Vector); { $0c is for com1/com3 - IRQ 4 }
  91. setintvec($0c,@AsyncInt);
  92. b:=port[INTCTLR];
  93. b:=b and $0ef;
  94. port[INTCTLR]:=b;
  95. b:=port[LCR];
  96. b:=b and $7f;
  97.  
  98. port[lcr]:=b;
  99. port[ier]:=enblrdy;
  100. port[mcr]:=$08 or MDMMOD;
  101. port[mdmmsr]:=mdmcd;
  102. port[$20]:=$20;
  103.  
  104. { when: port[MDMMSR] and $80 = $80 then there's carrier }
  105.  
  106. procedure sendchartoport(b: byte);
  107. begin
  108. while ( (port[lsr] and $20) <> $20 ) do
  109. begin
  110. end;
  111. port[dataport]:=b;
  112. end;
  113.  
  114. procedure sendstringtoport(s: string);
  115. var
  116. i:integer;
  117. begin
  118. for i:=1 to length(s) do
  119. sendchartoport(ord(S[i]));
  120. snedchartoport(13);
  121. end;
  122.  
  123. procedure disableports;
  124. var
  125. b: byte;
  126. begin
  127. sendstringtoport('ATC0');
  128. b:=port[intctlr];
  129. b:=b or $10;
  130. port[intctlr]:=b;
  131. b:=port[lcr];
  132. b:=b and $7f;
  133. port[lcr]:=b;
  134. port[ier]:=$0;
  135.  
  136. port[mcr]:=$0;
  137. port[$20]:=$20;
  138. setintvec($0c,vector);
  139. end;
  140.  
  141. { How the program itself should generally be }
  142.  
  143. begin
  144.  
  145. setmodem;
  146. enableports;
  147. send strings or chars
  148. disableports;
  149.  
  150. end.
  151.